#pragma once

#include <vector>

#include "../Common.h"

#include "Field.h"

namespace Chess
{
  class Board
  {
  public:
    Board(void);
    virtual ~Board(void);

    Field* GetField(unsigned x, unsigned y);
    virtual void Refresh(void);

    void SetField(Field* field, unsigned x, unsigned y);
    void ChangeStatus(FieldStatusEnum status, unsigned x, unsigned y);
    
    void DeselectAll(Chess::FieldStatusEnum status = Chess::FieldStatusEnum::SELECTED);
    void Select(unsigned x, unsigned y);    

    std::vector<XMFLOAT2> GetReachableFields(unsigned x, unsigned y);
    std::vector<XMFLOAT2> GetReachableFields(unsigned x, unsigned y, Chess::ColorEnum color);

    static const int LEN = 8;
  protected:
    Field* m_board[LEN][LEN];    
    unsigned Clamp(int x);

    void CalculatePawnPositions(unsigned x, unsigned y, Chess::ColorEnum color, std::vector<XMFLOAT2>* data);
    void CalculateKingPosistions(unsigned x, unsigned y, Chess::ColorEnum color, std::vector<XMFLOAT2>* data);
    void CalculateRookPosistions(unsigned x, unsigned y, Chess::ColorEnum color, std::vector<XMFLOAT2>* data);
    void CalculateBishopPosistions(unsigned x, unsigned y, Chess::ColorEnum color, std::vector<XMFLOAT2>* data);
    void CalculateQueenPosistions(unsigned x, unsigned y, Chess::ColorEnum color, std::vector<XMFLOAT2>* data);
    void CalculateKnightPosistions(unsigned x, unsigned y, Chess::ColorEnum color, std::vector<XMFLOAT2>* data);
  };
}
